<template>
	<el-dialog v-model="props.visible" :title="`添加回避机构`" width="80%" :before-close="close">
		<div>
			<HyTable
				v-if="props.visible"
				@sendSelectValue="getSelectValue"
				:searchFields="searchFields"
				:searchDefault="searchDefault"
				:tableConfig="tableConfig"
				:tableColumns="tableColumns"
				ref="hyTableRef"
			>
			</HyTable>
		</div>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="close">取消</el-button>
				<el-button type="primary" @click="sendData"> 确定 </el-button>
			</div>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import HyTable from '/@/components/HyTable/index.vue';
import { institutionInfoPageApi } from '/@/api/expertDatabase/institution';

const props = defineProps({
	visible: Boolean,
	selectValues: Array,
});
const searchFields = computed(() => {
	return {
		institutionName: {
			label: '机构名称',
			type: 'input',
		},
	};
});

watch(
	() => props.visible,
	() => {
		if (props.visible) {
			tableConfig.value = {
				request: institutionInfoPageApi,
				multiple: true,
				rowKey: 'institutionInfoId',
				selectValues: props.selectValues,
			};
		}
	}
);
const searchDefault = ref({
	status: '5',
});
//还原选择的数据
const hyTableRef = ref<any>();
const tableConfig: any = ref();
const tableColumns = computed(() => {
	return [{ prop: 'institutionName', label: '机构名称' }];
});
//关闭
const emits = defineEmits(['close']);
const close = () => {
	emits('close');
};
//获取选择的值
const selectValue = ref();
const getSelectValue = (value: any) => {
	selectValue.value = value;
};
//确定传递选择的值
const sendData = () => {
	emits('close', selectValue.value);
};
</script>

<style scoped lang="scss"></style>
